import axios from 'axios';
import config from '../config/index.js';

// 定义平台配置
const platformKeys = {
  sgj_teacher_weapp: {
    name: "幼儿园教师端",
    key: config.auth.accessKey
  },
  sgj_student_weapp: {
    name: "小学家长端",
    key: "A7FK9LP2QWE4ZXCR8VBNMJH5TGY6UD1S"
  },
  momoai: {
    name: "墨墨AI",
    key: "B8GM3NP5RWF6ZXDS9VCQMKJ7UHY2TE4A"

  }
};

export async function checkUserPermission(appId, appuserId, platform = "sgj_teacher_weapp") {

  let apps = [
    {
      // https://dify.ynzygh.com/app/834e56bd-f122-472d-98af-323d9588d524/develop
      // 学科强弱定位专业推荐
      appId: 1,
      name: "学科强弱定位专业推荐",
      APIkey: 'app-JEt0MqnMxCyhiPC86lj4h2cS',
    },
    {
      // https://dify.ynzygh.com/app/93c621f4-b71e-4983-a730-e3e994bd36db/develop
      // 性格兴趣专业推荐
      appId: 2,
      name: "性格兴趣专业推荐",
      APIkey: 'app-23EpTYekfnRY2bUr2IvNM2Fa',
    },
    {
      // https://dify.ynzygh.com/app/267f5cb9-abd8-4d02-970e-00dcf7836289/develop
      // 职业意向专业推荐
      appId: 3,
      name: "职业意向专业推荐",
      APIkey: 'app-KRsqNMrW7pJkHWCELZidKJW6',
    },
    {
      // https://dify.ynzygh.com/app/0be7128e-e269-4bd4-8bc5-3d3fe134cf0c/develop
      // 填报策略
      appId: 4,
      name: "填报策略",
      APIkey: 'app-DmqM9p7GhDBdm6BCE1nG4kbc',
    }
  ]
  let match = apps.find((item) => item.appId == appId);
  if (match) {
    return {
      success: true,
      message: "ok",
      ...match
    }
  } else {
    return {
      success: false,
      message: "未获取应用",
    }
  }
}


export async function saveDifyChatPaylog(appId, appuserId, token) {
  try {
    const checkRes = await axios({
      url: config.server.payLog,
      method: "POST",
      headers: {
        token
      },
      data: {
        appId,
        appuserId,
      },
    });
  } catch (error) {
    console.log("%c Line:91 🥤 error", "color:#fca650", error);

  }


}